{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fdcc61ac",
   "metadata": {},
   "source": [
    "-----------\n",
    "* 本学习记录人：戴祥哲\n",
    "* 学习时间：2021-11-25\n",
    "* week08\n",
    "* [参考文档](https://python.org/doc)\n",
    "* [徐老师博客](https://cnblogs.com/xuzhichao)\n",
    "-----------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0467c03a",
   "metadata": {},
   "source": [
    "购物车程序项目：\n",
    "\n",
    "要求：1、运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "\n",
    "　　   2、让用户输入商品编号进行商品的购买。\n",
    "\n",
    "　　   3、用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "\n",
    "　　   4、用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。\n",
    "\n",
    "...\n",
    "\n",
    "...\n",
    "1.用户输入余额=input()\n",
    "2.商品价格=[]\n",
    "3.打印数据print\n",
    "4.用户输入\n",
    "5.if else用户输入金额 同 选择商品价格 对比\n",
    "    1.钱够\n",
    "    2.钱不够\n",
    "6.\n",
    "...\n",
    "...\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a2faaed3",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的余额：5000000\n",
      "-------商品价格-------\n",
      "商品编号：0, 商品的名称:可乐 ,商品价格：3\n",
      "商品编号：1, 商品的名称:冰茶 ,商品价格：30\n",
      "商品编号：2, 商品的名称:血碧 ,商品价格：300\n",
      "商品编号：3, 商品的名称:奥力给 ,商品价格：3000\n",
      "商品编号：4, 商品的名称:milk ,商品价格：30000\n",
      "商品编号：5, 商品的名称:矿泉水 ,商品价格：300000\n",
      "请输入商品的编号(输入q退出购买)：1\n",
      "已经将【冰茶】放入你的购物车，你的余额还有【4999970】\n",
      "-------商品价格-------\n",
      "商品编号：0, 商品的名称:可乐 ,商品价格：3\n",
      "商品编号：1, 商品的名称:冰茶 ,商品价格：30\n",
      "商品编号：2, 商品的名称:血碧 ,商品价格：300\n",
      "商品编号：3, 商品的名称:奥力给 ,商品价格：3000\n",
      "商品编号：4, 商品的名称:milk ,商品价格：30000\n",
      "商品编号：5, 商品的名称:矿泉水 ,商品价格：300000\n",
      "请输入商品的编号(输入q退出购买)：111\n",
      "你选择的商品不存在，请输入正确的编号（输入q退出购买）\n",
      "-------商品价格-------\n",
      "商品编号：0, 商品的名称:可乐 ,商品价格：3\n",
      "商品编号：1, 商品的名称:冰茶 ,商品价格：30\n",
      "商品编号：2, 商品的名称:血碧 ,商品价格：300\n",
      "商品编号：3, 商品的名称:奥力给 ,商品价格：3000\n",
      "商品编号：4, 商品的名称:milk ,商品价格：30000\n",
      "商品编号：5, 商品的名称:矿泉水 ,商品价格：300000\n"
     ]
    }
   ],
   "source": [
    "#1. 商品列表\n",
    "goods_list = [\n",
    "        [\"可乐\",3],\n",
    "        [\"冰茶\",30],\n",
    "        [\"血碧\",300],\n",
    "        [\"奥力给\",3000],\n",
    "        [\"milk\",30000],\n",
    "        [\"矿泉水\",300000]\n",
    "]\n",
    "# 要添加用户的商品列表\n",
    "shopping_cart=[]\n",
    "#2. 用户输入\n",
    "Alipay = int(input(\"请输入你的余额：\"))\n",
    "\n",
    "# 3. 打印结果：商品编号：xxx ， 商品的名称：xxx ， 商品价格：xxx\n",
    "\n",
    "while True:   \n",
    "    print(\"-------商品价格-------\")\n",
    "    # 占位符\n",
    "    #print(\"商品编号：%s, 商品的名称:%s ,商品价格：%s\"%(0,goods_list[0][0],goods_list[0][1])) \n",
    "    for i in range(len(goods_list)):\n",
    "            print(\"商品编号：%s, 商品的名称:%s ,商品价格：%s\"%(i,goods_list[i][0],goods_list[i][1])) \n",
    "    # 4. 让用户输入商品编号进行商品的购买\n",
    "    choice = input(\"请输入商品的编号(输入q退出购买)：\")\n",
    "    #     Alipay VS 用户选择的商品的价格\n",
    "    \n",
    "    if choice.isdigit():\n",
    "        # 一、输入的是编号---------1.钱包够，扣钱，给Alipay赋值扣完之后的金额 2. 钱不够，提示用户\n",
    "        if int(choice) >=0 and int(choice) < len(goods_list):\n",
    "            if Alipay >=goods_list[int(choice)][1]:\n",
    "                Alipay = Alipay - goods_list[int(choice)][1]\n",
    "                shopping_cart.append(goods_list[int(choice)])\n",
    "                print(\"已经将【%s】放入你的购物车，你的余额还有【%s】\"%(goods_list[int(choice)][0],Alipay))\n",
    "            else:\n",
    "                print(\"你的余额已不足，滚犊子吧\")\n",
    "        else:\n",
    "            print(\"你选择的商品不存在，请输入正确的编号（输入q退出购买）\")\n",
    "    elif choice == \"q\":\n",
    "    #二、用户输入‘q’退出\n",
    "        print(\"你的购物车有【%s】，你的余额还有【%s】\"%(shopping_cart,Alipay))\n",
    "        break\n",
    "        \n",
    "    else:\n",
    "        # 三、 用户输入什么都不是\n",
    "        print(\"你输入错了，是不是傻！（输入q退出购买）\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b73f187",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(5):\n",
    "   "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
